import { defineStore } from "pinia";
import { store } from "@/store";
import { darkTheme } from 'naive-ui'
export const themeStore = defineStore({
    id: "app-theme",
    state: () => ({
        theme:'light',
        themeConfig:ref(null)
    }),
    getters: {
        getTheme(): string {
            return this.theme;
        },
        getThemeConfig(): any {
            return this.themeConfig;
        }
    },
    actions: {
        setTheme(info?: string | undefined) {
            this.theme = info ? info : "light";
            // @ts-ignore
            this.themeConfig = info === 'dark' ? darkTheme : null
            if (this.theme === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches) {
                document.documentElement.classList.add('dark')
            } else {
                document.documentElement.classList.remove('dark')
            }
        },
    },
});
// 导出外部使用
export function useThemeStore() {
    return themeStore(store);
}
